extends State
class_name PlayerState

var animated_sprite_2d: AnimatedSprite2D
var player: CharacterBody2D;
var gravity_magnitude = ProjectSettings.get_setting("physics/2d/default_gravity")

var play_run_speed = 200 # 奔跑速度
var jump_power = -500 # 跳跃力
var input_direction;
var is_press_jump = false # 按下跳跃
var is_release_jump = false # 松开跳跃
var is_on_wall = false
func Enter() -> void:
	# 1. 类型断言：确保 actor 是我们需要的 CharacterBody2D 类型
	# player.gd 脚本上有一个 animated_sprite_2d 的导出变量，我们可以直接获取
	assert(actor is CharacterBody2D, "PlayerState requires a CharacterBody2D actor.")
	assert(actor.animated_sprite_2d != null, "Actor 没有 AnimatedSprite2D")
	animated_sprite_2d = actor.animated_sprite_2d
	player = actor

func Physic_Update(_delta:float) -> void:
	is_on_wall = player.is_on_wall()
	input_direction = Input.get_axis(&"Left",&"Right")
	is_press_jump = Input.is_action_just_pressed(&"Jump")
	is_release_jump = Input.is_action_just_released(&"Jump")
#	全局重力加速度	
	player.velocity.y+=_delta*gravity_magnitude
	player.move_and_slide()
